﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using XZL.GM.Bll;
using XZL.GM.Dal;
public partial class Course_Comment : AdminBasePage
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            txtStart.Text = DateTime.Now.AddMonths(-1).ToString("yyyy-MM-dd");
            txtEnd.Text = DateTime.Now.ToString("yyyy-MM-dd");
            BindCommentList();
            BindCourseName();
        }
    }

    private void BindCourseName()
    {
        try
        {
            string str = Request.QueryString["CourseID"];
            int courseID = Convert.ToInt32(str);
            Proc_CourseInfo_SelectInfoResult course = CourseInfoBiz.GetCourseInfo(courseID);

            txtCourseName.Text =" 课程名称："+course.CourseName;
        }
        catch { }
    }



    private void BindCommentList()
    {

        DateTime start = new DateTime();
        DateTime end = new DateTime();
     
        try
        {
            start = Convert.ToDateTime(txtStart.Text);
            end = Convert.ToDateTime(txtEnd.Text);
            end = end.AddDays(1);
        }
        catch (Exception ex)
        {
            lblWarn.Text = "请输入正确的日期格式！";
            return;
        }

        int? count = 0;
        string str = Request.QueryString["CourseID"];
        int courseID = Convert.ToInt32(str);

        divCondition.Visible = true;
        gridList.DataSource = CommentInfo.GetCommentList(courseID, start, end, netPager.CurrentPageIndex, netPager.PageSize, ref count);
        gridList.DataBind();
        netPager.RecordCount = count.Value;
       
    }

    /// <summary>
    /// 获取状态
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    protected string DGFormatSex(string Status)
    {
        if (Status == "-1")
        { return "禁用"; }

        else if (Status == "1")
        { return "启用"; }

        
        return "";
    }

    /// <summary>
    /// 点击 审核
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    protected void gridList_RowDeleting(object sender, GridViewDeleteEventArgs e)
    {
        string commentID = gridList.DataKeys[e.RowIndex]["CommentID"].ToString();
        string courseID = Request.QueryString["CourseID"];
         //  string commentID = Request.QueryString["CommentID"];
        Proc_CommentInfo_SelectInfoResult comment = CommentInfo.GetCommentInfo(commentID);

        int s = 0;
        if (comment.Status == -1)
        {
            s = 1;
        }
        else if (comment.Status == 1)
        {
            s = -1;
        }

       bool b = CommentInfo.ChangeStatus(commentID, s);
       
       if (b)
       {        
            Response.Redirect("Comment.aspx?CourseID=" + courseID);
           
       }
       else
       {
           lblWarn.Text = "更新失败！";
       }
      
    }

   
    /// <summary>
    /// 分页控件
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    protected void netPager_PageChanged(object sender, EventArgs e)
    {
        BindCommentList();
    }

    protected void btnSelect_Click(object sender, EventArgs e)
    {
        BindCommentList();
        netPager.CurrentPageIndex = 1;
    }

  
}